package com.cnunicom.modules.revival.controller;

import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.cnunicom.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cnunicom.modules.revival.entity.RevivalProvinceEntity;
import com.cnunicom.modules.revival.service.RevivalProvinceService;
import com.cnunicom.common.utils.PageUtils;
import com.cnunicom.common.utils.R;



/**
 * 乡村振兴,省份
 *
 * @author dingziyuan
 * @email dzy998877@163.com
 * @date 2019-07-05 11:37:30
 */
@RestController
@RequestMapping("revival/revivalprovince")
public class RevivalProvinceController extends AbstractController {
    @Autowired
    private RevivalProvinceService revivalProvinceService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("revival:revivalprovince:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = null;
        params.put("user", getUser());
        try {
            page = revivalProvinceService.queryPage(params);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("revival:revivalprovince:info")
    public R info(@PathVariable("id") Long id){
		RevivalProvinceEntity revivalProvince = revivalProvinceService.getById(id);

        return R.ok().put("revivalProvince", revivalProvince);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("revival:revivalprovince:save")
    public R save(@RequestBody RevivalProvinceEntity revivalProvince){
        Date date = new Date();
        revivalProvince.setCreateTime(date);
        revivalProvince.setUpdateTime(date);
        revivalProvince.setCreateUserId(getUserId());
        revivalProvinceService.save(revivalProvince);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("revival:revivalprovince:update")
    public R update(@RequestBody RevivalProvinceEntity revivalProvince){
        revivalProvince.setUpdateTime(new Date());
		revivalProvinceService.updateById(revivalProvince);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("revival:revivalprovince:delete")
    public R delete(@RequestBody Long[] ids){
		revivalProvinceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
